//
//  YLRealNameAuthenticationViewController.m
//  YLFinanceService
//
//  Created by she1323 on 2017/9/4.
//  Copyright © 2017年 she1323. All rights reserved.
//

#import "YLRealNameAuthenticationViewController.h"
#import "YLRealNameInformationProgress.h"
#import <Masonry.h>
#import "YLGlobeHeader.h"
#import "YLMyInfoViewController.h"
#import "YLCertifiedPaymentViewController.h"

@interface YLRealNameAuthenticationViewController ()<YLMyInfoViewControllerDelegate>
@property (nonatomic, weak) YLRealNameInformationProgress *progress;
@property (nonatomic, weak) UIView *payMentView;
@property (nonatomic, weak) UINavigationBar *bar;
@end

@implementation YLRealNameAuthenticationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    __weak typeof(self) weakSelf = self;
    YLRealNameInformationProgress *progress = [YLRealNameInformationProgress progress];
    _progress = progress;
    [self.view addSubview:progress];
    [progress mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.view).mas_offset(YLOffsetY);
        make.left.right.mas_equalTo(weakSelf.view);
        make.height.mas_equalTo(YLScreenW * 185 / 747.0);
    }];
    
    self.navigationItem.title = @"实名信息";
    
    
    
    YLMyInfoViewController *myInfo = [[YLMyInfoViewController alloc] init];
    myInfo.delegate = self;
    [self addChildViewController:myInfo];
    
    YLCertifiedPaymentViewController *payMent = [[YLCertifiedPaymentViewController alloc] init];
    [self addChildViewController:payMent];
    
    [self.view addSubview:myInfo.view];
    
    self.view.backgroundColor = YLColor(248, 249, 252);
    [self.view addSubview:payMent.view];
    
    [myInfo.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.mas_equalTo(weakSelf.view);
        make.width.mas_equalTo(weakSelf.view);
        make.top.mas_equalTo(progress.mas_bottom);
    }];
    
    __weak typeof(UIView) *myInfoView = myInfo.view;

    [payMent.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(myInfoView);
        make.width.mas_equalTo(myInfoView);
        make.right.mas_equalTo(myInfoView.mas_left);
    }];
    _payMentView = payMent.view;
    _payMentView.hidden = YES;
    
    if (self.navigationController.childViewControllers.count > 1) {
        WHNavBackButton *backButton = [WHNavBackButton navBackButton];
        [backButton setImage:[UIImage imageNamed:@"fanhuijianblack"] forState:UIControlStateNormal];
        [backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    }
}

- (void)back
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

- (void)myInfoViewControllerSure:(YLMyInfoViewController *)controller realNameModel:(YLRealNameModel *)model
{
    _payMentView.hidden = NO;
    //YLCertifiedPaymentViewController *con = self.childViewControllers.lastObject;
   // con.realNameModel = model;
    self.navigationItem.title = @"认证支付";
    [_progress next];
    [self.view layoutIfNeeded];
    __weak typeof(self) weakSelf = self;
    [_payMentView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.mas_equalTo(weakSelf.view);
        make.width.mas_equalTo(weakSelf.view);
        make.top.mas_equalTo(weakSelf.progress.mas_bottom);
       }];
    [UIView animateWithDuration:0.35 animations:^{
        [weakSelf.view layoutIfNeeded];
    }];
}



- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    _bar = self.navigationController.navigationBar;
    [self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:YLColor(50, 50, 50)};
    // 修改状态栏颜色
    self.navigationController.navigationBar.barStyle = UIStatusBarStyleDefault;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [_bar setBackgroundImage:[UIImage imageNamed:@"navBackground"] forBarMetrics:UIBarMetricsDefault];
    // 修改标题颜色
    _bar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
    // 修改状态栏颜色
    _bar.barStyle = UIStatusBarStyleLightContent;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}



@end
